package cn.yd.rb.controller;

import cn.yd.rb.po.News;
import cn.yd.rb.po.Novel;
import cn.yd.rb.po.Type;
import cn.yd.rb.service.NewsService;
import cn.yd.rb.service.NovelService;;
import cn.yd.rb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
@Controller
public class IndexController {

    @Autowired
    private NovelService novelService;
    @Autowired
    private NewsService newsService;
    @Autowired
    private UserService userService;
    @RequestMapping("/index")
    public String index(Model model) throws  Exception{
        //获取新闻列表
        List<News> newsList =newsService.findNewsAll();
        model.addAttribute("newsList",newsList);
        //获取分类列表
        List<Type> noveltypeList = novelService.findNoveltype();
        model.addAttribute("noveltypeList",noveltypeList);
        //获取下载量排行榜
        List<Novel> novelHotList = novelService.findNovelHot();
        model.addAttribute("novelHotList",novelHotList);
        //获取滚动图片
        List<Novel> novelSliderList = novelService.findNovelSlider();
        model.addAttribute("novelSliderList",novelSliderList);
        //获取编辑推荐--按评分
        List<Novel> novelRecList = novelService.findNovelRec();
        model.addAttribute("novelRecList",novelRecList);
        //获取编辑推荐--按评分和下载量
        List<Novel> novelDownList = novelService.findNovelDowm();
        model.addAttribute("novelDownList",novelDownList);
        return "index";
    }
}
